<?php
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
	include '../../connection/connection.php';
	include "../../value/value_kr.php";	
	
	$winH = $_REQUEST['winH'];
	
	$list=$_SESSION['sort'];
	$str=$_GET['string'];
	$_SESSION['sortn']=$str;
	$flagDesc=$_GET['flagDesc'];
	
	$carnumber = $_REQUEST['carnumber'];
	
	$fromdate = $_REQUEST['fromdate'];
	$hourfrom = $_REQUEST['hourfrom'];
	$minutefrom = $_REQUEST['minutefrom'];
	$secondfrom = $_REQUEST['secondfrom'];
	
	$todate = $_REQUEST['todate'];
	$hourto = $_REQUEST['hourto'];
	$minuteto = $_REQUEST['minuteto'];
	$secondto = $_REQUEST['secondto'];
	
	if($flagDesc==1){

		if($list[$str]=="DESC")
			$list[$str]="ASC";
		else
			$list[$str]="DESC";
	}
	$selectcount = mysql_query("SELECT COUNT(*) as total FROM carcrime cc ,caruser cs,configcamera co where cs.iUser=cc.iuser and co.id=cc.cameraID ", $connection);
	$count = mysql_fetch_assoc($selectcount);
	
	$sql = "SELECT cs.szUser,cs.iUser,cc.*,co.name FROM carcrime cc ,caruser cs,configcamera co where cs.iUser=cc.iuser and co.id=cc.cameraID ";
	
	if ($_REQUEST['carnumber'] !=''){
		$sql.=" and cc.carnum like '%".$carnumber."%' ";
	}
	
	if ($_REQUEST['fromdate'] != "" && $_REQUEST['todate'] != ""){
		$sql.= " and cc.regDatetime >= '".$_REQUEST['fromdate']." ".$hourfrom.":".$minutefrom.":".$secondfrom." ' and cc.regDatetime <= '".$_REQUEST['todate']." ".$hourto.":".$minuteto.":".$secondto." '" ;
	}else{
		if ($_REQUEST['fromdate'] != ""){
			$sql.= " and cc.regDatetime >= '".$_REQUEST['fromdate']." ".$hourfrom.":".$minutefrom.":".$secondfrom." ' and cc.regDatetime <= '".$_REQUEST['fromdate']." ".$hourto.":".$minuteto.":".$secondto." '" ;
		}else if ($_REQUEST['todate'] != ""){
			$sql.= " and cc.regDatetime >= '".$_REQUEST['todate']." ".$hourto.":".$minuteto.":".$secondto." ' and cc.regDatetime <= '".$_REQUEST['todate']." ".$hourto.":".$minuteto.":".$secondto." '" ;
		}
	}
	
	$selectallcarcrime = mysql_query($sql." ORDER BY ".$str." ".$list[$str], $connection);

	$_SESSION['sort']=$list;
	
	?>
	<div style="overflow:scroll;overflow-x: hidden; width:100%; height:<?php echo ($winH-240)."px"?>; background-color: #ffffff">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebody2">
            <tbody>
             <?php 
            		$i = 0;
           		while ($rowcarcrime = mysql_fetch_array($selectallcarcrime)) {
             		$i++;?>
	            <tr>
	           		<td style="width: 5%"><?=$i;?></td>
	                <td style="width: 15%"><?=$rowcarcrime[carnum]?></td>
	                <td style="width: 10%"><?=$rowcarcrime[regDatetime]?></td>
	                <td style="width: 25%"><?php if ($rowcarcrime[regMemo]==''){echo "&nbsp;";}else{?> <?=$rowcarcrime[regMemo]?><?php }?></td>
	                <td style="width: 25%"><?php if ($rowcarcrime[regNote]==''){echo "&nbsp; ";}else{?> <?=$rowcarcrime[regNote]?><?php }?></td>
	                <td  class="last" style="width: 20%"><?=$rowcarcrime[szUser]?></td>
	            </tr>
               <?php
                		 }
					if ($i>0 and $i<($winH/28)) {
							 	foreach(range(0,($winH/28)-$i) as $real){
							 		?>
							 		<tr>
								 		<td width="5%">&nbsp;</td>
								 		<td width="15%">&nbsp;</td>
								 		<td width="10%">&nbsp;</td>
									 	<td width="25%">&nbsp;</td>
									 	<td width="25%">&nbsp;</td>
									 	<td class="last" style="width: 20%;border-right: none !important;">&nbsp;</td>
								 	</tr>
							 	<?php }
							}?>
            </tbody>              
        </table>
        </div>
         <div>
	       	<table>
	       		<tr>
				    <td class="rf-dt-ftr-carcrime-user" style="text-align: left;padding-top: 15px; " colspan="7">
					<label style="color: white;padding-left: 15px;">  <?php echo $l_totalrecord?> <?=$count[total]?></label>
					</td>
						
				</tr>	
	       	</table>
	      </div>
             <?php mysql_close($connection);?>      